home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SATAN11.ZIP / HTML / REPORTIN / SORT_HOS.PL < prev   
Encoding:
Text File  |  1995-04-01  |  4.2 KB  |  172 lines

  1. #
  2. # Display a list of hosts sorted on some attribute; hosts may be member
  3. # of more than group.
  4. #
  5.  
  6. &make_severity_info();
  7.  
  8. $_sort_title = "";
  9. %_sort_group = ();
  10. $_sort_sub = "";
  11. %_not_linked = ();
  12. $_sort_note = "";
  13.  
  14. #
  15. # Factor out sort-order dependent code.
  16. #
  17.  
  18. sub sort_alpha {
  19.         $a cmp $b;
  20. }
  21.  
  22. sub sort_severity {
  23.     $_res = ($severity_host_count{$b} <=> $severity_host_count{$a});
  24.     return ($_res != 0) ? $_res : $a cmp $b;
  25. }
  26.  
  27. sub sort_ip {
  28.     local($aip,$bip);
  29.     for $ip (split(/\./,$a)) { $aip = $aip * 256 + $ip; }
  30.     for $ip (split(/\./,$b)) { $bip = $bip * 256 + $ip; }
  31.     return $aip <=> $bip;
  32. }
  33.  
  34. $_sort_toc = "sort_alpha";
  35.  
  36. if ($_sort_order eq "" || $_sort_order eq "name") {
  37.     $_sort_group{""} = join(' ', @_hosts);
  38. } elsif ($_sort_order eq "severity") {
  39.     $_sort_group{""} = join(' ', @_hosts);
  40.     $_sort_sub = "sort_severity";
  41. } elsif ($_sort_order eq "subnet") {
  42.     &make_subnet_info();
  43.     $_sort_title = "Subnet";
  44.     $_sort_link = "satan_results_subnet.pl";
  45.     for (@_hosts) { $_sort_group{$host_subnet{$_}} .= "$_ "; }
  46.     $_sort_toc = "sort_ip";
  47. } elsif ($_sort_order eq "type") {
  48.     &make_hosttype_info();
  49.     $_sort_title = "System type";
  50.     $_sort_link = "satan_info_OStype.pl";
  51.     for (@_hosts) { $_sort_group{$hosttype{$_}} .= "$_ "; }
  52. } elsif ($_sort_order eq "domain") {
  53.     &make_domain_info();
  54.     $_sort_title = "Internet domain";
  55.     $_sort_link = "satan_results_domain.pl";
  56.     for (@_hosts) { $_sort_group{$host_domain{$_}} .= "$_ "; }
  57. } elsif ($_sort_order eq "severity_type") {
  58.     $_sort_title = "Problem type";
  59.     $_sort_link = "satan_severity_hosts.pl";
  60.     for $_host (@_hosts) {
  61.         if (exists($severity_host_type_info{$_host})) {
  62.             for $_type (keys %{$severity_host_type_info{$_host}}) {
  63.                 $_sort_group{$_type} .= "$_host ";
  64.             }
  65.         } else {
  66.             $_type = "(none)";
  67.             $_sort_group{$_type} .= "$_host ";
  68.             $_not_linked{$_type} = 1;
  69.         }
  70.     }
  71.     $_sort_note = "Note: a host may appear in more than one category.";
  72. } elsif ($_sort_order eq "trusted_type") {
  73.     $_sort_title = "Hosts trusted by $_trustee";
  74.     for $_host (@_hosts) {
  75.         for $_type (keys %{$trust_host_type{"$_host $_trustee"}}) {
  76.             $_sort_group{$_type} .= "$_host ";
  77.             $_not_linked{$_type} = 1;
  78.         }
  79.     }
  80.     $_sort_note = "Note: a host may appear in more than one category.";
  81. } elsif ($_sort_order eq "trustee_type") {
  82.     $_sort_title = "Hosts trusting $_trusted";
  83.     for $_host (@_hosts) {
  84.         for $_type (keys %{$trust_host_type{"$_trusted $_host"}}) {
  85.             $_sort_group{$_type} .= "$_host ";
  86.             $_not_linked{$_type} = 1;
  87.         }
  88.     }
  89.     $_sort_note = "Note: a host may appear in more than one category.";
  90. }
  91.  
  92. #
  93. # Make a nice table of contents.
  94. #
  95.  
  96. if ($_sort_title) {
  97.     print CLIENT <<EOF;
  98.     <hr>
  99.     <h3>$_sort_title: table of contents.</h3>
  100.     <ul>
  101. EOF
  102.     for $_group (sort $_sort_toc keys %_sort_group) {
  103.         $_count = $_bad = 0;
  104.         for $_host (split(/\s/, $_sort_group{$_group})) {
  105.             $_count++;
  106.             $_bad++ if exists($severity_host_type_info{$_host});
  107.         }
  108.         $_dot = $_bad ? "reddot" : "blackdot";
  109.         $_alt = $_bad ? "*" : "-";
  110.         $_counts = ($_bad != $_count) ? "($_bad/$_count)" : "($_count)";
  111.         print CLIENT <<EOF;
  112.         <dt><IMG SRC="$HTML_ROOT/dots/$_dot.gif" ALT="$_alt"> 
  113.         <a href="#$_group">$_group</a> $_counts
  114. EOF
  115.     }
  116.     print CLIENT <<EOF;
  117.     </ul>
  118.     $_sort_note
  119.     <hr>
  120. EOF
  121. }
  122.  
  123. #
  124. # Finally, list all those groups and their respective host members.
  125. #
  126.  
  127. $_sort_sub = "sort_alpha" if $_sort_sub eq "";
  128.  
  129. for $_group (sort $_sort_toc keys %_sort_group) {
  130.     if ($_sort_title) {
  131.         print CLIENT <<EOF;
  132.         <h3>
  133.         <a name="$_group">
  134.         $_sort_title: 
  135. EOF
  136.         if ($_not_linked{$_group}) {
  137.             print CLIENT <<EOF;
  138.             $_group.
  139. EOF
  140.         } else {
  141.             ($_GROUP = $_group) =~ tr / \//?!/;
  142.             print CLIENT <<EOF;
  143.             <a href="$_sort_link,$_GROUP,">$_group</a>.
  144. EOF
  145.         }
  146.         print CLIENT <<EOF;
  147.         </h3>
  148. EOF
  149.     }
  150.     print CLIENT <<EOF;
  151.     <ul>
  152. EOF
  153.     for (sort $_sort_sub split(/\s/, $_sort_group{$_group})) {
  154.         if ($severity_host_count{$_}) {
  155.             $_dot = "reddot";
  156.             $_alt = "*";
  157.             $_bad = "($severity_host_count{$_})";
  158.         } else {
  159.             $_dot = "blackdot";
  160.             $_alt = "-";
  161.             $_bad = "";
  162.         }
  163.         print CLIENT <<EOF;
  164.         <dt><IMG SRC=$HTML_ROOT/dots/$_dot.gif ALT="$_alt"> 
  165.         <a href="satan_info_host.pl,$_,"> $_</a> $_bad
  166. EOF
  167.     }
  168.     print CLIENT <<EOF;
  169.     </ul>
  170. EOF
  171. }
  172.